package leencode;

import org.junit.jupiter.api.Test;

import java.util.HashMap;

public class no26_删除有序数组中的重复项 {



    @Test
    public void  test(){

        HashMap hashMap = new HashMap();
        hashMap.put(1,1);
        hashMap.remove(1);

        System.out.println(3/2);

        int[] ints = {-1,0,0,0,0,3,3};
        removeDuplicates(ints);

        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }
    public int removeDuplicates(int[] nums) {
        int[] res = new int[nums.length];
        res[0] = nums[0];
        int k = 1;
        for (int i = 1; i < nums.length; i++) {
            boolean dup = true;
            for (int j = 0; j < res.length; j++) {
                if (nums[i] == res[j] || nums[i] == 0) {
                    dup = false;
                    break;
                }
            }
            if(dup) res[k++] = nums[i];
        }

        for (int i = 1; i < nums.length; i++) {
            nums[i] = res[i];
        }

        return k;
    }


    public static int removeDuplicates2(int[] nums) {
        int k = 1;
        for (int i = 1; i < nums.length; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] == nums[j]) {

                    break;
                }
                if (j == i-1){
                    if (i != k){
                        nums[k] = nums[i];
                    }
                    k++;
                    break;
                }
            }
        }

        return k;
    }

}
